import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/registered',
    component: () => import('@/views/registered/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/course',
    children: [
      {
        path: 'course',
        name: 'Course',
        component: () => import('@/views/course/index'),
        meta: { title: '视频教学' }
      },
      {
        path: 'courseDetail/:id',
        name: 'CourseDetail',
        component: () => import('@/views/course/courseDetail'),
        meta: { title: '课程详情' },
        hidden: true
      }
    ]
  },

/*   {
    path: '/train',
    component: Layout,
    children: [
      {
        path: 'train',
        component: () => import('@/views/train/index'),
        name: 'Train',
        meta: { title: '题库训练' }
      }
    ]
  }, */

  {
    path: '/onlineExam',
    component: Layout,
    children: [
      {
        path: 'onlineExam',
        name: 'OnlineExam',
        component: () => import('@/views/onlineExam/index'),
        meta: { title: '在线考试' }
      },
      {
        path: '/testPage/:examId/:readOnly',
        name: 'TestPage',
        component: () => import('@/views/testPage/preview'),
        meta: { title: '考试页' },
        hidden: true
      },
      {
        path: '/exam/start/:id',
        component: () => import('@/views/paper/exam/exam'),
        name: 'StartExam',
        meta: { title: '开始考试' },
        hidden: true
      },
      {
        path: '/exam/result/:id',
        component: () => import('@/views/paper/exam/result'),
        name: 'ShowExam',
        meta: { title: '考试结果' },
        hidden: true
      },

    ]
  },
  {
    path: '/report',
    // redirect: '/report/index',
    component: Layout,
    children: [
      {
        path: 'report',
        name: 'Report',
        component: () => import('@/views/report/index'),
        meta: { title: '报告中心' }
      },
      {
        path: 'editReport/:id',
        name: 'EditReport',
        component: () => import('@/views/report/editReport'),
        meta: { title: '编辑报告' },
        hidden: true
      },
      {
        path: 'contrast/:id',
        name: 'Contrast',
        component: () => import('@/views/report/contrast'),
        meta: { title: '报告结果' },
        hidden: true
      }
    ]
  },
  {
    path: '/exam',
    component: Layout,
    children:[
      {
        path: '/records',
        component: () => import('@/views/user/exam/my'),
        name: 'ListMyExam',
        meta: { title: '我的成绩' }
      },
      {
        path: 'book/list/:examId',
        component: () => import('@/views/user/book'),
        name: 'BookList',
        meta: { title: '考试错题' },
        hidden: true
      },

      {
        path: 'book/training/:examId',
        component: () => import('@/views/user/book/train'),
        name: 'BookTraining',
        meta: { title: '错题训练'},
        hidden: true
      },
    ]
  },

]

const createRouter = () =>
  new Router({
    mode: 'hash', // 修改为 hash 模式
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
